<template>
  <div class="titles-view">
    <div class="titles-container">
      <!-- 页面头部 -->
      <div class="page-header">
        <el-button class="header-back" @click="goBack">
          <el-icon><ArrowLeft /></el-icon>
          返回
        </el-button>
        <h1 class="page-title">称号管理</h1>
        <p class="page-subtitle">查看和管理您的所有称号</p>
      </div>
      
      <!-- 称号管理组件 -->
      <div class="titles-content" v-if="currentUserId">
        <UserTitlesManager :userId="currentUserId" />
      </div>
      
      <div v-else class="no-user">
        <el-empty description="请先登录以查看称号">
          <el-button type="primary" @click="goToLogin">去登录</el-button>
        </el-empty>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'
import { ArrowLeft } from '@element-plus/icons-vue'
import UserTitlesManager from '@/components/user/UserTitlesManager.vue'

const router = useRouter()
const userStore = useUserStore()

const currentUserId = computed(() => {
  return userStore.user?.id || userStore.user?.userId || userStore.user?.uid
})

const goBack = () => {
  router.back()
}

const goToLogin = () => {
  router.push('/login')
}
</script>

<style scoped>
.titles-view {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}

.titles-container {
  max-width: 1200px;
  margin: 0 auto;
}

.page-header {
  text-align: center;
  margin-bottom: 40px;
  position: relative;
}

.header-back {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.9);
  border: none;
  color: #374151;
}

.page-title {
  color: white;
  font-size: 2.5rem;
  font-weight: 700;
  margin: 0 0 16px 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.page-subtitle {
  color: rgba(255, 255, 255, 0.9);
  font-size: 1.1rem;
  margin: 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.titles-content {
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.no-user {
  background: white;
  border-radius: 16px;
  padding: 60px 20px;
  text-align: center;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

@media (max-width: 768px) {
  .titles-view {
    padding: 10px;
  }
  
  .page-title {
    font-size: 2rem;
  }
  
  .header-back {
    position: relative;
    margin-bottom: 20px;
    transform: none;
  }
}
</style>
